#! /bin/bash

ns=$1
app_name=$2

pod_name=`kubectl -n $ns get pods | grep $app_name`
pod_count=`echo "$pod_name" | wc -l`
if test "$pod_count" != "1"; then
    echo "Choose pod: "
    echo "$pod_name" | grep -n ''
    read index
    pod_name=`echo "$pod_name" | awk "NR==$index {print \\$1; exit}"`
else
    pod_name=`echo "$pod_name" | awk '{print $1}'`
fi

echo "kubectl -n $ns exec $pod_name -- ${@:3}"
kubectl -n $ns exec $pod_name -- "${@:3}"
